package sol.leetcode;

import java.util.Arrays;

/**
 * Single Number III
 */
public class Issue260 {
    public int[] singleNumber(int[] nums) {
        int diff = 0;
        for (int num : nums)
            diff ^= num;
        diff = Integer.highestOneBit(diff);
        int[] res = {0, 0};
        for (int num : nums) {
            if ((num & diff) == 0)
                res[0] ^= num;
            else
                res[1] ^= num;
        }
        return res;
    }

    public static void main(String[] args) {
        int[] nums = {1, 2, 1, 3, 2, 5};
        System.out.println(Arrays.toString(new Issue260().singleNumber(nums)));
    }

}
